/*
 ============================================================================
 Name		: FlashLightView.cpp
 Author	  : 
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CFlashLightView implementation
 ============================================================================
 */
#include <aknviewappui.h>
#include "FlashLightView.h"
#include "LemonAssistant.hrh"
#include <LemonAssistant.rsg>
#include "LemonAssistantAppUi.h"

CFlashLightView::CFlashLightView()
	{
	// No implementation required
	iContainer = NULL;
	}

CFlashLightView::~CFlashLightView()
	{
	DoDeactivate();
	}

CFlashLightView* CFlashLightView::NewLC()
	{
	CFlashLightView* self = new (ELeave) CFlashLightView();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

CFlashLightView* CFlashLightView::NewL()
	{
	CFlashLightView* self = CFlashLightView::NewLC();
	CleanupStack::Pop(); // self;
	return self;
	}

void CFlashLightView::ConstructL()
	{
	BaseConstructL(R_FLASH_LIGHT_VIEW);
	}

TUid CFlashLightView::Id() const
	{
	return TUid::Uid(ELemonAssistantAppViewFlashLight);
	}

void CFlashLightView::HandleCommandL(TInt aCommand)
	{
	switch (aCommand)
		{
		case ECommandOperateOpen:
			STATIC_CAST(CLemonAssistantAppUi*,CEikonEnv::Static()->AppUi())
						->SetCommandSetL(R_FLASH_LIGHT_OPTIONS_SET_BACK_CLOSE);
			iContainer->Light();
			break;
		case ECommandOperateClose:
			STATIC_CAST(CLemonAssistantAppUi*,CEikonEnv::Static()->AppUi())
						->SetCommandSetL(R_FLASH_LIGHT_OPTIONS_SET_BACK_OPEN);
			iContainer->Light();
			break;
		case EAknSoftkeyBack:
			AppUi()->ActivateLocalViewL(TUid::Uid(ELemonAssistantAppViewMain));
			break;
		default:
			AppUi()->HandleCommandL(aCommand);
		}
	}

void CFlashLightView::HandleStatusPaneSizeChange()
	{
	if (iContainer != NULL)
		iContainer->SetRect(ClientRect());
	}

/**
 * 
 * */
void CFlashLightView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
		TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
	{
	if (iContainer == NULL)
		{
		iContainer = CFlashLightContainer::NewL(ClientRect());
		iContainer->SetMopParent(this);
		AppUi()->AddToStackL(*this, iContainer);

		//add your init code ...

		}
	}
void CFlashLightView::DoDeactivate()
	{
	if (iContainer != NULL)
		{
		AppUi()->RemoveFromViewStack(*this, iContainer);
		delete iContainer;
		iContainer = NULL;
		}
	}
